{layout name="public/tab_layout" /}
<div class="layui-container">  
<div class="layui-row">
<div class="layui-col-xs10 layui-col-xs-offset1">

        <form class="layui-form" action="">
                <input type=text name="id" value="{$info.id}" style="display:none">
                <div class="layui-form-item">
                  <label class="layui-form-label">名称</label>
                  <div class="layui-input-inline">
                    <input type="text" name="name"autocomplete="off" placeholder="请输入名称" class="layui-input" value="{$info.name}">
                  </div>
                </div>

                <div class="layui-form-item">
                        <label class="layui-form-label">上级</label>
                        <div class="layui-input-inline">
                                <select name="parent_id"  lay-search="">
                                  <option value="0">一级</option>
                                  {volist name="arr" id="vo"}  
                                  <option value="{$vo.id}" {if condition="$vo.id == $info.parent_id"}selected=""{/if} {if condition="$vo.id == $info.id OR ($vo.parent_id == $info.id AND $info.id != 0)"}disabled=""{/if}>{$vo.name}</option>
                                  {/volist}
                                </select>
                        </div>
                </div>

                <div class="layui-form-item">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-inline">
                          <input type="text" name="description"  autocomplete="off"class="layui-input" value="{$info.description}">
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-inline">
                          <input type="text" name="sort" autocomplete="off" class="layui-input"  value="{$info.sort}">
                        </div>
                </div>
        </form>
        
</div>
</div>

<div class="layui-row">
        <div class="layui-col-xs4 layui-col-xs-offset4">

                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-normal btn_save">保存</button>
                    {if condition="0 != $info.id"}
                    <button class="layui-btn layui-btn-danger btn_delete">删除</button>
                    {/if}
                </div>
        </div>
</div>      

</div>

<script>
layui.use('form', function(){
    var form = layui.form;
});
//绑定按钮
$(function(){
    $('.btn_save').on('click',function(){
	    //读取输入框的值
	    var value = {
            id: $("input[name='id']").val(),
            name: $("input[name='name']").val(),
            parent_id: $("select[name='parent_id']").val(),
            description: $("input[name='description']").val(),
            sort: $("input[name='sort']").val(),
        };
        $.post("{:url('Warehouse/Console/category_save')}", value,
            function(ret) {
            var status = "1" == ret.status ? "success": "error";
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                setTimeout("parent.location.reload();",1000);//1秒后刷新父类
            }
            
        },"json")
    })
    //删除
    $('.btn_delete').on('click',function(){
	    //读取输入框的值
	    var value = {
            id: $("input[name='id']").val(),
        };
        $.post("{:url('Warehouse/Console/category_delete')}", value,
            function(ret) {
            var status = "1" == ret.status ? "success": "error";
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                setTimeout("parent.location.reload();",1000);//1秒后刷新父类
            }else{
                layer.msg('操作失败！请检查是否有下级分类或物料');
            }
            
        },"json")
    })
})
</script>